package com.txts.road.app.track.controller;

import com.txts.road.app.track.model.dto.LocationPointDTO;
import com.txts.road.app.track.model.dto.TrackRecordDTO;
import com.txts.road.app.track.model.query.TrackRecordQuery;
import com.txts.road.app.track.model.vo.TrackRecordVO;
import com.txts.road.app.track.service.TrackRecordService;
import com.txts.base.common.domain.ResponseDTO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.*;

import jakarta.validation.Valid;

import java.util.List;

/**
 * 轨迹记录前端控制层
 *
 * @author baoyr
 * @since 2025-07-17 10:43
 */
@Tag(name = "轨迹记录接口")
@RestController
@RequestMapping("/api/v1/track-record")
@RequiredArgsConstructor
public class TrackRecordController {
    private final TrackRecordService trackRecordService;


    /**
     * 开始记录轨迹
     */
    @Operation(summary = "开始记录轨迹")
    @PostMapping("/start")
    public ResponseDTO<Long> startTrackRecord(@Valid @RequestBody TrackRecordDTO startDTO) {
        return ResponseDTO.ok(trackRecordService.startTrackRecord(startDTO));
    }

    /**
     * 停止记录轨迹
     */
    @Operation(summary = "停止记录轨迹")
    @PostMapping("/{trackId}/stop")
    public ResponseDTO<Boolean> stopTrackRecord(@PathVariable Long trackId) {
        return ResponseDTO.ok(trackRecordService.stopTrackRecord(trackId));
    }

    /**
     * 上传位置点
     */
    @Operation(summary = "上传位置点")
    @PostMapping("/{trackId}/location")
    public ResponseDTO<Boolean> uploadLocationPoint(@Parameter(description = "轨迹id") @PathVariable Long trackId,
                                                    @Valid @RequestBody LocationPointDTO pointDTO) {
        return ResponseDTO.ok(trackRecordService.uploadLocationPoint(trackId, pointDTO));
    }

    /**
     * 批量上传位置点
     */
    @Operation(summary = "批量上传位置点")
    @PostMapping("/{trackId}/locations/batch")
    public ResponseDTO<Boolean> batchUploadLocationPoints(@Parameter(description = "轨迹id") @PathVariable Long trackId,
                                                          @Valid @RequestBody List<LocationPointDTO> points) {
        return ResponseDTO.ok(trackRecordService.batchUploadLocationPoints(trackId, points));
    }

    /**
     * 获取轨迹列表
     */
    @Operation(summary = "获取轨迹列表")
    @PostMapping("/list")
    public ResponseDTO<List<TrackRecordVO>> getTrackList(@Valid @RequestBody TrackRecordQuery query) {
        return ResponseDTO.ok(trackRecordService.getTrackList(query));
    }

    /**
     * 获取轨迹详情
     */
    @Operation(summary = "获取轨迹详情")
    @GetMapping("/{trackId}")
    public ResponseDTO<TrackRecordVO> getTrackDetail(@PathVariable Long trackId) {
        return ResponseDTO.ok(trackRecordService.getTrackDetail(trackId));
    }

    /**
     * 删除轨迹
     */
    @Operation(summary = "删除轨迹")
    @DeleteMapping("/{trackId}")
    public ResponseDTO<Boolean> deleteTrack(@PathVariable Long trackId) {
        return ResponseDTO.ok(trackRecordService.deleteTrack(trackId));
    }


}
